
#ifndef __SSH_SERVER_SSHD
#define __SSH_SERVER_SSHD 1
#include <libssh/server.h>
#include <event/ssh_epoll_event.h>
/**
 *  实现ssh 服务端实现，并且通过客户端实现数据转发功能对象
 * @author: gtinlian
 * @email: gtinlian@sina.com
*/
class SSHServer
{
private:
    string rsa_key = "./server_rsa_key";
    string host_key = "./host_key";
    string host = "0.0.0.0";
    string port = "221";
    ssh_bind sshbind;

    /** 服务连接认证 */
    static int auth_pass(ssh_session session, const char *user, const char *password, void *userdata);
    static int auth_none_callback(ssh_session session, const char *user, void *userdata);
    static int request_callback(ssh_session session, const char *service, void *userdata);
    static int auth_pubkey(ssh_session session, const char *user, struct ssh_key_struct *pubkey,char signature_state, void *userdata);
    static ssh_channel open_channel(ssh_session session, void *userdata);

    /** 数据传输控制 */
    static int pty_request(ssh_session session, ssh_channel channel,const char *term, int cols, int rows, int py, int px, void *userdata);
    static int pty_resize(ssh_session session, ssh_channel channel, int cols, int rows, int py, int px, void *userdata);
    static int shell_request(ssh_session session, ssh_channel channel,         void *userdata);
    static int exec_request(ssh_session session, ssh_channel channel, const char *command, void *userdata);
    static int data_function(ssh_session session, ssh_channel channel, void *data,     uint32_t len, int is_stderr, void *userdata);
    static int subsystem_request(ssh_session session, ssh_channel channel,    const char *subsystem, void *userdata);
    static int env_request_function (ssh_session session,ssh_channel channel,const char *env_name,const char *env_value,void *userdata);
public:
    EpollSSHEvent *ep;
    SSHServer();
    SSHServer(string ras_path, string host_key,string host,string port){
        this->host = host;
        this->rsa_key = rsa_key;
        this->host_key = host_key;
        this->port = port;
    }

    bool status(){
        if(sshbind != nullptr){
            return true;
        }else{
            return false;
        }
    }
    void accept();
    ~SSHServer(){
        if(this->sshbind != nullptr)
        ssh_bind_free(sshbind);
    }
    void handel(ssh_session session);
    static void call_handel(SSHServer *ss, ssh_session session);
};

#endif